<?php 
namespace XFCore\traits\api;
trait WxDyTrait{
    public function dy_status($get , $data){
        $this->verifyip();
        $requiredFields = ['wx_name', 'status'];
        if($this->checkRequiredParams($requiredFields , $data)){
            $this->echomsg('json','参数不全');
        }
        $data['wx_name'] = urldecode($data['wx_name']);
        $dyrow = $this->db->wechat_trumpetrow($data['wx_name'] , 'wx_name','`id`');
        if(empty($dyrow)){
            $this->echomsg('json','店员不存在');
        }
        if($this->db->update('wechat_trumpet',$data , ['id'=>$dyrow['id']])){
            exitjson(200,'更新成功！');
        }
        exitjson(-1,'更新失败！');
    }
    public function wxpay_zt_Out($get , $data){
        $this->verifyip();
        if(empty($data['wx_name'])){
            $this->echomsg('json',"店长微信名为空");
        }
        $arr = [
            'login_time' =>time()+60,
            'wxname'=>urldecode($data['intl_wx_name']),
            'endtime'=>$this->date,
            'status'=>1
        ];
        
        if($this->db->update('qrlist',$arr , ['beizhu'=>$data['wx_name']])){
            exitjson(200,'更新状态成功！');
        }
        
        exitjson(-1,'更新微信状态失败,可能不存在此微信二维码');
    }
    
    public function dy_notify($get , $data){
        $this->verifyip();
        $data = input();
        $name   = $data['name'];
        $money  = $data['money'];
        if(empty($name) || empty($money)){
            $this->echomsg('json','参数不全');
        }
        $qr_row = $this->db->qrlistrow($name , 'beizhu' , 'pid');
        
        if(empty($qr_row)){
            $this->echomsg('json','二维码数据不存在！');
        }
        $pid  = $qr_row['pid'];
        $userrow = $this->db->userrow($pid , 'pid',"`pid`,`key`,`user`,`email`");
        if(empty($userrow)){
            $this->echomsg('json','用户数据不存在！');
        }
        $time = time();
        $E_type = ['wxpay'=>'微信店员'];
        $srow = $this->db->select('order',"*",['status'=>0,'price'=>$money , 'outtime'=>['operator'=>'gt','value'=>$time] , 'pid'=>$pid , 'type'=>'wxpay'],['single_row'=>true,'limit'=>1])['result'];
        if(!empty($srow) && $srow['status'] == 0){
            $this->get_notify($E_type , $srow , $userrow);
            exitjson(200,'订单回调成功',['order'=>$srow['trade_no']]);
        }
        exitjson(-1,'此金额匹配不到金额');
    }
    protected function verifyip(){
        $ips = explode('|',$this->conf['wxip']);
        if(!in_array(http_ip(),$ips)){
            $this->echomsg('json',"IP验证不通过".http_ip()."，请在后台计划任务中添加白名单");
        }
        
    }
}

?>